package com.suptrack.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.suptrack.entity.Car;
import com.suptrack.entity.User;
import com.suptrack.service.CarService;
import com.suptrack.service.UserService;

/**
 * Servlet implementation class ManageCarServlet
 */
@WebServlet("/RegisteredContent/ManageCar")
public class ManageCarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
@EJB
CarService carservice;
@EJB
UserService userservice;

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession Session= request.getSession();
		User usersession =(User) Session.getAttribute("User");
		if(usersession != null){
		
			User user = userservice.getUserInfo(usersession.getId());
			List<Car> _carlist = user.getCar();
			usersession.setCar(_carlist);
			
			Session.setAttribute("User", usersession);
			request.setAttribute("CarList", _carlist);
		}
		request.getRequestDispatcher("/RegisteredContent/ManageCars.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
